<template>
  <div class="app-container">
    <el-steps :active="active" finish-status="success">
      <el-step title="编辑课程信息"></el-step>
      <el-step title="创建课程大纲"></el-step>
      <el-step title="最终发布"></el-step>
    </el-steps>
    <div class="ccInfo">
      <img :src="coursePublish.cover" alt="图片丢失">
      <div class="main">
        <h2>{{ coursePublish.title }}</h2>
        <p class="gray"><span>共{{ coursePublish.lessNum }}课时</span></p>
        <p><span>所属分类：{{ coursePublish.subjectOne }} — {{ coursePublish.subjectTwo }}</span></p>
        <p>课程讲师：{{ coursePublish.teacherName }}</p>
        <h3 class="red">￥{{ coursePublish.price }}</h3>
      </div>
    </div>

    <el-form label-width="120px">
      <el-form-item>
        <el-button style="margin-top: 12px;" @click="prev">返回上一页修改数据</el-button>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate">确认无误,发布课程</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { getPublishVo, publish } from '@/api/edu/course'

  export default {
    data() {
      return {
        coursePublish: {},
        saveBtnDisabled: false,
        active: 2
      }
    },
    created() {
      this.getCoursePublishVo(this.$route.params.id)
    },
    methods: {
      saveOrUpdate() {
        publish(this.$route.params.id).then(response => {
          this.$message.success('发布成功!')
        }).catch(error => {
          this.$message.error('该课程已发布!')
        })
        this.$router.push({ path: '/edu/course/list' })
      },
      prev() {
        const id = this.$route.params.id
        this.$router.push({ path: '/edu/course/chapter/' + id })
      },
      getCoursePublishVo(courseId) {
        getPublishVo(courseId).then(response => {
          this.coursePublish = response.data.coursePublishVo
        })
      }

    }
  }
</script>

<style scoped>
  .ccInfo {
    background: #f5f5f5;
    padding: 20px;
    overflow: hidden;
    border: 1px dashed #DDD;
    margin-bottom: 40px;
    position: relative;
  }

  .ccInfo img {
    background: #d6d6d6;
    width: 500px;
    height: 278px;
    display: block;
    float: left;
    border: none;
  }

  .ccInfo .main {
    margin-left: 520px;
  }

  .ccInfo .main h2 {
    font-size: 28px;
    margin-bottom: 30px;
    line-height: 1;
    font-weight: normal;
  }

  .ccInfo .main p {
    margin-bottom: 10px;
    word-wrap: break-word;
    line-height: 24px;
    max-height: 48px;
    overflow: hidden;
  }

  .ccInfo .main p {
    margin-bottom: 10px;
    word-wrap: break-word;
    line-height: 24px;
    max-height: 48px;
    overflow: hidden;
  }

  .ccInfo .main h3 {
    left: 540px;
    bottom: 20px;
    line-height: 1;
    font-size: 28px;
    color: #d32f24;
    font-weight: normal;
    position: absolute;
  }
</style>
